package com.chinaisafe.user.controller;

import com.chinaisafe.base.common.validated.UpdateGroup;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.chinaisafe.base.common.annotation.OperationLog;
import com.chinaisafe.base.common.enums.BusinessTypeEnum;
import com.chinaisafe.base.common.validated.AddGroup;
import com.chinaisafe.base.common.vo.Answer;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.chinaisafe.user.vo.request.SysAccountReqVO;
import com.chinaisafe.user.vo.response.SysAccountRespVO;
import org.springframework.validation.annotation.Validated;
import com.chinaisafe.user.service.SysAccountService;
import org.springframework.web.bind.annotation.RestController;

/**
 * SysAccountController
 * Description：账号接口层
 *
 * @author xuefu.shu
 * @date  2024-07-12 09:55:54
 */
@RestController
@RequestMapping("/sysAccount")
@Tag(name = "账号接口层", description = "账号接口层")
public class SysAccountController {

    @Autowired
    private SysAccountService sysAccountService;

    @GetMapping("/pageList")
    @Operation(summary = "获取账号分页列表", description = "获取账号分页列表")
    public Answer<IPage<SysAccountRespVO>> pageList(SysAccountReqVO sysAccountReqVO) {
        IPage<SysAccountRespVO> pageList = sysAccountService.getPageList(sysAccountReqVO);
        return Answer.success("获取成功", pageList);
    }

    @PostMapping()
    @Operation(summary = "新增账号", description = "新增账号")
    @OperationLog(title = "账号-新增", businessType = BusinessTypeEnum.INSERT)
    public Answer<SysAccountRespVO> add(@RequestBody @Validated(AddGroup.class) SysAccountReqVO sysAccountReqVO) {
        SysAccountRespVO sysAccountRespVO = sysAccountService.add(sysAccountReqVO);
        return Answer.success("保存成功", sysAccountRespVO);
    }

    @PutMapping()
    @Operation(summary = "根据id编辑账号", description = "根据id编辑账号")
    @OperationLog(title = "账号-根据id编辑", businessType = BusinessTypeEnum.UPDATE)
    public Answer<SysAccountRespVO> update(@RequestBody @Validated(UpdateGroup.class) SysAccountReqVO sysAccountReqVO) {
        SysAccountRespVO sysAccountRespVO = sysAccountService.update(sysAccountReqVO);
        return Answer.success("修改成功", sysAccountRespVO);
    }

    @GetMapping("/{sysAccountId}")
    @Operation(summary = "根据id获取账号", description = "根据id获取账号")
    public Answer<SysAccountRespVO> getDetailById(@PathVariable Long sysAccountId) {
        SysAccountRespVO sysAccountRespVO = sysAccountService.getDetailById(sysAccountId);
        return Answer.success("获取成功", sysAccountRespVO);
    }

    @DeleteMapping()
    @Operation(summary = "根据id删除账号", description = "根据id删除账号")
    @OperationLog(title = "账号-根据id删除", businessType = BusinessTypeEnum.DELETE)
    public Answer<Void> deleteByIds(@RequestParam("ids") Long[] ids) {
        sysAccountService.deleteByIds(ids);
        return Answer.success("删除成功");
    }
}

